<!-- 首页 -->
<template>
	<view class="page">
		<view class="user-box border-bottom" v-for="(item, index) in dataList" :key="index">
			<view>
				<view class="status-a" v-if="item.status == 0">{{item.remark}}</view>
				<view class="status-b" v-else>已完成</view>
				<view class="user-tag">{{item.createTime}}</view>
			</view>
			<view class="coin-btn">
				<view class="coin-num">{{item.coinNum}}</view>
				<u-icon name="qiandai" custom-prefix="iconfont"></u-icon>
			</view>
		</view>
		
		<view class="empty-text" v-if="dataList.length == 0">暂无记录</view>
		<view class="loadmore-box" v-if="dataList.length > 0">
			<u-loadmore :status="status" @loadmore="load"></u-loadmore>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		userId: {
			type: String,
			default: 0
		}
	},
	data() {
		return {
			form: {
				lon: '',
				lat: '',
			},
			status: 'loadmore',
			scrollTop: 0,
			isEnd: false,
			current: 1,
			pageSize: 20,
			dataList: [],
		};
	},
	created() {
		this.init();
	},
	methods: {
		init() {
			this.query();
		},
		load() {
			this.loadmore();
		},
		async loadmore() {
			this.status = 'loading';
			if(this.isEnd){
				this.status = 'nomore';
				return;
			}
			var res = await this.getDataList();
			this.dataList = this.dataList.concat(res.rows);
		},
		query() {
			this.current = 1;
			this.isEnd = false;
			this.status = 'loadmore';
			this.loadquery();
		},
		async loadquery() {
			var res = await this.getDataList();
			this.dataList = res.rows;
		},
		async getDataList() {
			var res = await this.$u.get('/pay/userCoin/getCoinByUserId', {
				pageNum: this.current,
				pageSize: this.pageSize,
				userId: this.userId,
			});
			var totalPage = Math.ceil(res.total/this.pageSize);
			this.pages = totalPage;
			this.current ++;
			this.status = 'loadmore';
			if(this.current > this.pages){
				this.status = 'nomore';
				this.isEnd = true;
			}
			return res;
		},
	}
};
</script>
<style lang="scss" scoped>
	.page {
		padding-bottom: 176rpx;
		background-color: #fff;
		padding: 0 15px;
	}
	.user-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 0;
	}
	.user-name-box {
		display: flex;
		align-items: center;
	}
	.nickname {
		font-size: 28rpx;
		margin-right: 5px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		max-width: 100px;
	}
	.sex-box {
		background-color: #2b85e4;
		display: flex;
		color: #fff;
		padding: 4rpx 10rpx;
		border-radius: 20px;
		font-size: 16rpx;
	}
	.sex-box-nv {
		background-color: #fe709f;
		display: flex;
		color: #fff;
		padding: 4rpx 10rpx;
		border-radius: 20px;
		font-size: 16rpx;
	}
	.user-tag-box {
		display: flex;
		align-items: center;
	}
	.user-tag {
		font-size: 20rpx;
		color: #82848a;
	}
	.user-box-right {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex: 1;
	}
	.sign-name {
		font-size: 24rpx;
		color: #8d8d8d;
		text-overflow: ellipsis;
		width: 400rpx;
		overflow: hidden;
		white-space: nowrap;
	}
	.renzheng-box {
		display: flex;
		align-items: center;
		margin-right: 5px;
	}
	.line {
		float:left;
		width: 1px;
		height: 16rpx; 
		background: #e5e5e5;
		margin: 0 5px;
	}
	.vip-box {
		color: #fff;
		margin-left: 5px;
		font-size: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #f7ce05;
		padding: 4rpx 8rpx;
		border-radius: 20px;
	}
	.vip-text {
		font-size: 16rpx;
	}
	.empty-text {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100px;
		color: #b4adad;
	}
	.loadmore-box {
		padding: 15px;
	}
	.coin-btn {
		display: flex;
		align-items: center;
		color: #d09494;
		font-weight: bold;
		font-size: 28rpx;
	}
	.coin-num {
		margin-right: 5px;
	}
	.status-a {
		font-size: 10px;
		color: #fff;
		background-color: #decdcd;
		padding: 3px 8px;
		border-radius: 20px;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 60px;
		margin-bottom: 10px;
	}
	.status-b {
		font-size: 10px;
		color: #fff;
		background-color: #6b76ff;
		padding: 3px 8px;
		border-radius: 20px;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 60px;
		margin-bottom: 10px;
	}
	.border-bottom {
		position: relative;
	}
	.border-bottom:before {
		content: " ";
		width: 200%;
		height: 200%;
		position: absolute;
		top: 0;
		left: 0;
		border-bottom: 1rpx solid #f4f4f5;
		-webkit-transform: scale(0.5);
		transform: scale(0.5);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		box-sizing: border-box;
	}
</style>
